<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit,Vue.prototype.$vFN.Utils],
  components: {
  },
  data() {
    return {
      appWindow: window,
      form: {
        adminCount: 0,
        id: 0,
        name: "",
        remark: "",
        platformId: "",
        permission_ids: [],
      },

      // 页面接口地址
      apiUrl: {
        create: "store/role/add",
        update: "store/role/edit",
        detail: "store/role/detail",
      },
      listCanAuthRole: [],
      defaultProps: {
        children: "children",
        label: "label",
      },
    };
  },
  methods: {
    // 初始化
    async init() {
      // 初始化数据
      await this.mixinEdit_editBoxInit({
        model: "form",
        id: this.id,
        onInit: async () => {
          // 获取用户信息
          let _data = await this.$vFN.Http.post({
            url: "store/role/menu",
          },window);
          if (_data._ok) {
            this.listCanAuthRole = JSON.parse( JSON.stringify(_data.data.list).replace(/menu_title/g, "label"));   
            this.getArrayValue(this.listCanAuthRole);
          }
          return true;
        },
      });
      // this.mixinTable_refreshData();
    },
    
    mixinEdit_editDataExtend(data_) {

      if (this.mixinEdit_editType == "add") {
      }
      if (this.mixinEdit_editType == "update") {
        // 有返回null展示出来, 修改成空字符串
        data_.remark =  this.$vFN.Utils.isEmpty(data_.remark) == true ? '' :  data_.remark;
      }

      return data_;
    },
    
    // 查询全部权限ID,转成数字类型
    getArrayValue(array){
        for(let i=0; i<array.length; i++){
           array[i].id = Number(array[i].id);
           
           if(array[i].children.length >= 1){
              this.getArrayValue(array[i].children);
           }

        }
    },  

    handleNodeClick(data) {
      let array = this.$refs.tree.getCheckedKeys();
      this.form.permission_ids = [];

      for (let arr of array) {
        this.form.permission_ids.push(arr);
      }

      //点击切换没有清空数据
    //  console.log(this.form.permission_ids);
    //  console.log(this.$refs.tree.getCheckedKeys());
    },
  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>